<?php
namespace Core\URL;

class URL {
    
    public function __construct($url = null) {
        if(isset($_SERVER['HTTP_REFERER'])) {
            $url = $url ? $url : $_SERVER['HTTP_REFERER'];
            if(strlen($url) > 0) {
                $this->prepareURL($url);
            }
        }
    }
    
    public function prepareURL($url) {
        parse_str($url, $urlProperties);
        foreach ($urlProperties as $name => $value) {
            $this->$name = $value;
        }
    }
    
    public function __get($name) {
        if ( DEBUG || DEBUG_URL ) {
            return $this->$name = 'NULL';
        }
        
        return $this->$name = null;
    }
}